﻿@{
    Layout = null;
}

@using CNKI.TPI.Web.Search.Model;
@using CNKI.TPI.Web.Base
<script>

    //组全选
    function securitycheckall(e) {
        if ($(e).attr("checked") == "checked") {
            $(".checkboxsecurity input[type='checkbox']").each(function () {
                $(this).attr("checked", "checked");
            })
        }
        else {
            $(".checkboxsecurity input[type='checkbox']").each(function () {
                $(this).removeAttr("checked", "checked");
            })
        }
    }
    $(".checkboxsecurity input[type='checkbox']").click(function () {
        //循环判断列表中的checkbox，如果全部选中则全选框呈勾选状态
        var m = 0;
        if ($(this).attr("checked") != "checked") {
            $("input.securityall").removeAttr("checked", "checked");
        }
        else {
            $(".checkboxsecurity input[type='checkbox']").each(function () {
                if ($(this).attr("checked") != "checked") {
                    m = 1;
                }
            })
            if (m == 1) {
                $("input.securityall").removeAttr("checked", "checked");
            }
            else {
                $("input.securityall").attr("checked", "checked");
            }
        }

    })
    //删除多选
    function delsecuritiylist() {
        var ckbs = $(".checkboxsecurity input[type='checkbox']:checked");
        if (ckbs.size() == 0) {
            messageAlert("请选择要删除的记录！");
            return;
        }
        confirmDialog('确定要删除吗?', function () {
            var checkedstr = [];
            ckbs.each(function () {
                checkedstr.push($(this).val());
            })
            var delurl = "@Html.Raw(Url.Action("DelSecurity", "Admin_User"))";
            var data = { "idlist": checkedstr.toString() };
            dealdata(delurl, data);
        })

    }
    function setvalue() {
        var s = [];
        var v = [];
        $('table tbody tr').each(function () {
            s.push($(this).children().eq(1).text());
            v.push($(this).children().eq(2).text());
        })
        $("#usename").html(s.toString());
        $("#usevalue").html(v.toString());
    }
    //添加组
    function addsecuritiy() {
        $("#FlageID").val(0);
        $(".talkDiv-title span").html("添加密级");
        $(".span4").val("");
        $(".span5").val("");
        setvalue();
        showsecuritiy();
    }
    //编辑
    function modifysecuritiy(sysid, name, value, descript) {
        $("#FlageID").val(sysid);
        $(".talkDiv-title span").html("编辑密级");
        $("#securitiyname").val(name);
        $("#securitiyvalue").val(value);
        $("#securitiydescript").val(descript);
        setvalue();
        showsecuritiy();
    }
    //删除密级
    function delsecuritiy(sysid) {
        var delurl = "@Html.Raw(Url.Action("DelSecurity", "Admin_User"))";
        var data = { "idlist": sysid };
        confirmDialog('确定要删除吗?', function () {
            dealdata(delurl, data);
        })
    }
    function closesecuritiy() {
        $(".talkDivBg").hide();
        $(".form-h").hide();
    }
    function showsecuritiy() {
        $(".talkDivBg").show();
        $(".form-h").show();
    }
    //调用controll
    function dealdata(urlstr, datastr) {
        $.ajax({
            type: "POST",
            url: urlstr,
            data: datastr,
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    ajaxLoad("initload", '@Html.Raw(Url.Action("SecurityIndex", "Admin_User"))');
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }

    function savesecuritiy() {
        var secname = $.trim($("#securitiyname").val());
        var secvlaue = $("#securitiyvalue").val();
        if (secname == "") {
            messageAlert("请输入密级名称！");
            return;
        }
        else {
            if (!regtext(secname)) {
                messageAlert("请输入密级名称(不允许输入特殊字符)！");
                return;
            }
        }
        if ($.trim(secvlaue) == "") {
            messageAlert("请输入密级值！");
            return;
        }
        else {
            if (!regnum0(secvlaue)) {
                messageAlert("请输入密级值(正整数和0)！");
                return;
            }
        }
        if ($("#securitiydescript").val() != "") {
            if (!regtext($("#securitiydescript").val())) {
                messageAlert("请输入密级描述(不允许输入特殊字符)！");
                return;
            }
        }
        var sysid = $("#FlageID").val();
        var m = 0; //判断密级名称，密级值是否重复
        $.ajax({
            type: "GET",
            async: false,
            data: { "name": secname, "value": secvlaue, "sysid": sysid },
            url: timestamp("@Html.Raw(Url.Action("IsExitSecurity", "Admin_User"))"),
            success: function (obj) {
                if (obj == 1) {
                    messageAlert("该密级名称已经存在！");
                    m = 1;
                }
                else if (obj == 2) {
                    messageAlert("该密级值已经存在！");
                    m = 1;
                }
            },
            error: function (e)
            { }
        })
        if (m == 0) {
            var insertdata = { "Name": secname, "Value": secvlaue, "Type": "1", "SysID": sysid, "Descript": $("#securitiydescript").val() };
            var saveurl = "@Html.Raw(Url.Action("SaveSecurity", "Admin_User"))";
                var savedata = { "obj": insertdata };
                $.ajax({
                    type: "POST",
                    url: saveurl,
                    data: JSON.stringify(savedata),
                    contentType: "application/json",
                    success: function (m) {
                        if (m == "True") {
                            messageAlert("操作成功！");
                            closesecuritiy();
                            ajaxLoad("initload", '@Html.Raw(Url.Action("SecurityIndex", "Admin_User"))');
                    }
                    else {
                        messageAlert("操作失败！");
                    }
                },
                error: function (e)
                { }
            })
        }

    }

</script>
<style>
    .f-lb {
        text-align: right;
    }
</style>
<div class="wrapR-c" style="padding-top: 20px">
    <input hidden="hidden" id="FlageID" type="hidden" />
    <div class='posr' style="padding-bottom: 20px">

        <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="addsecuritiy()">添加</a>
        <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="delsecuritiylist()">删除</a>
    </div>
    <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
        <thead>
            <tr class="thead">
                <th class="tdnum">
                    <input type="checkbox" class="securityall" value="" name="" onclick="securitycheckall(this)">序号</th>
                <th class=''>密级名称</th>
                <th class=''>密级对应值</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @{if (ViewBag.SecurityList != null)
              {
                  int sortno = 1;
                  foreach (SYS_CMS_SECURITY item in ViewBag.SecurityList)
                  {
                      string str = "even";
                      if (sortno % 2 == 0)
                      {
                          str = "odd";
                      }
                <tr class='@str'>
                    <td class="checkboxsecurity">
                        <input type="checkbox" value="@item.SysID"  >@sortno</td>
                    <td style="text-align: center">@item.Name</td>
                    <td style="text-align: center">@Html.Raw(item.Value)</td>
                    <td class="tc">
                        <a onclick="modifysecuritiy('@item.SysID','@item.Name','@item.Value','@item.Descript')" href="javascript:void(0)">编辑</a>
                        <a onclick="delsecuritiy('@item.SysID')" href="javascript:void(0)">删除</a>
                    </td>
                </tr>
                      sortno = sortno + 1;
                  }
              }

            }
        </tbody>
    </table>
</div>
  <!--透明背景-->
    <div class="talkDivBg" style="display: none; z-index: 999">
    <!--talkDiv弹出层(不带图片，宽550)-->
    <div class="talkDiv talkW-550 form-h form-h-8em" style='margin-top: -135px; display: none'>
        <div class="talkDiv-title">
            <span>添加密级</span>
            <a class="icon icon-close" title="关闭" onclick="closesecuritiy()" href="javascript:void(0);"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1 ">

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">密级名称：</label>
                </div>
                <div class="f-ct">
                    <input type="text" value="" class="f-text span4" id="securitiyname" maxlength="64">
                    <span class="f-label-re">*</span>
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">密级对应的值：</label>
                </div>
                <div class="f-ct">
                    <input type="text" value="" class="f-text span4" onkeyup="value=value.replace(/[^\d.]/g,'')" id="securitiyvalue" maxlength="9">
                    <span class="f-label-re">*(正整数和0)</span>
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">已使用密级名称：</label>
                </div>
                <div class="f-ct">
                    <span id="usename" style="height: auto; width: 400px; word-break: break-all;word-wrap: break-word;display:inline-block"></span>
                </div>
            </div>
            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">已使用的值：</label>
                </div>
                <div class="f-ct">
                    <span id="usevalue" style="height: auto; width: 400px; word-break: break-all;word-wrap: break-word;display:inline-block"></span>
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">密级描述：</label>
                </div>
                <div class="f-ct">
                    <textarea rows="4" class="f-textarea span5" id="securitiydescript" maxlength="254"></textarea>
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label"></label>
                </div>
                <div class="f-ct" style="margin-left: 150px">
                    <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="savesecuritiy()">保存</a>
                    &#12288;<a href="javascript:void(0);" class="btn btn-m btn-submit btn-defa-f" onclick="closesecuritiy()">取消</a>
                </div>
            </div>

        </div>
    </div>
</div>
